package io.github.topcatv.mall.common.ao;

import io.github.topcatv.mall.model.sys.entity.Permission;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.cglib.beans.BeanCopier;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 操作权限
 *
 * @author liuyi
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PermissionAo implements Serializable {
    private static final BeanCopier PERMISSION_COPIER = BeanCopier.create(Permission.class, PermissionAo.class, false);
    private static final BeanCopier ENTITY_COPIER = BeanCopier.create(PermissionAo.class, Permission.class, false);
    public final static int TYPE_MENU = Permission.TYPE_MENU;
    public final static int TYPE_ACTION = Permission.TYPE_ACTION;

    @ApiModelProperty(value = "权限名")
    private String name;
    @ApiModelProperty(value = "权限层级")
    private Integer level;
    @ApiModelProperty(value = "权限类型", allowableValues = "1,2", notes = "1: 菜单权限， 2: 功能权限")
    private Integer type;
    @ApiModelProperty(value = "菜单名")
    private String title;
    @ApiModelProperty(value = "页面路由路径")
    private String path;
    @ApiModelProperty(value = "前端vue组件名")
    private String component;
    @ApiModelProperty(value = "菜单icon图标")
    private String icon;
    @ApiModelProperty(value = "权限描述")
    private String description;
    @ApiModelProperty(value = "菜单排序")
    private BigDecimal sortOrder;
    @ApiModelProperty(value = "权限状态")
    private Boolean enabled;
    @ApiModelProperty(value = "外部链接")
    private String url;
    @ApiModelProperty(value = "上级菜单")
    private Integer parentId;

    public PermissionAo(Permission permission) {
        PERMISSION_COPIER.copy(permission, this, null);
    }

    public Permission toEntity() {
        Permission permission = new Permission();
        ENTITY_COPIER.copy(this, permission, null);
        return permission;
    }
}
